

package jetbrains.buildServer.server.rest.model;

import java.util.Map;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import jetbrains.buildServer.server.rest.swagger.annotations.ModelBaseType;
import jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription;
import jetbrains.buildServer.server.rest.swagger.constants.ObjectType;
import jetbrains.buildServer.server.rest.util.ValueWithDefault;
import org.jetbrains.annotations.NotNull;

/**
 * @author Yegor.Yarko
 *         Date: 01/03/2016
 */
@SuppressWarnings("PublicField")
@XmlRootElement(name = "metaData")
@ModelDescription("Represents a named Entries entity.")
@ModelBaseType(
    value = ObjectType.DATA,
    baseEntity = "Entries"
)
public class NamedData {
  @XmlAttribute
  public String id;

  @XmlElement(name = "entries")
  public Entries entries;

  public NamedData() {
  }

  public NamedData(
    @NotNull String nameP,
    @NotNull Map<String, String> properties,
    @NotNull Fields fields
  ) {
    id = ValueWithDefault.decideIncludeByDefault(fields.isIncluded("id"), nameP);

    entries = ValueWithDefault.decideIncludeByDefault(fields.isIncluded("entries"), () ->
      new Entries(properties, fields.getNestedField("entries"))
    );
  }
}